package com.class05.advice;

import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @ClassDescription: 使用普通方式进行事务的添加
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/11/3 16:23
 */
@Component
@Aspect
@Order(10) //指定一个优先级的值，值越小  优先级越高！越高前置首先执行，后置后执行
public class TxAdvice {
    @Before(value = "com.class05.pointcut.MyPointCut.pc()")
    public void begin(){
        System.out.println("TxAdvice开启事务");
    }
    @AfterReturning(value = "com.class05.pointcut.MyPointCut.pc()",returning = "result")
    public void commit(Object result){
        System.out.println("TxAdvice事务提交,计算结果为："+result);
    }
    @After("com.class05.pointcut.MyPointCut.pc()")
    public void after() {
        System.out.println("TxAdvice方法结束了");
    }
    @AfterThrowing(value = "com.class05.pointcut.MyPointCut.pc()",throwing = "t")
    public void rollback(Throwable t){
        System.out.println("事务回滚，错误信息是："+t);
    }
}
